import book.BookList;
import operation.Ioperation;
import user.AdminUser;
import user.CommonUser;
import user.User;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:何人亮
 * Date:2024-05-24
 * 21:20
 */
public class Main {
    public static User login(){
        System.out.println("**********欢迎进入图书管理系统**********");
        System.out.println("请输入你的姓名：");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();
        System.out.println("请选择你的身份 1：管理员  2：普通用户");
        int choice=scanner.nextInt();
        if(choice==1){
            String ss= scanner.nextLine();
            System.out.println("请输入管理员密码：");
            String password1=scanner.nextLine();
            while(true){
                if(password1.equals(AdminUser.password)){
                    break;
                }else {
                    System.out.println("密码错误，请重新输入");
                    password1=scanner.nextLine();
                }
            }
            return new AdminUser(name);
        }
        else{
            String ss= scanner.nextLine();
            System.out.println("请输入普通用户密码：");
            String password1=scanner.nextLine();
            while(true){
                if(password1.equals(CommonUser.password)){
                    break;
                }else {
                    System.out.println("密码错误，请重新输入");
                    password1=scanner.nextLine();
                }
            }
            return new CommonUser(name);
        }
    }


    public static void main(String[] args) {
        BookList bookList=new BookList();
       while (true){
           User user=login();

           while(true){
               int choice=user.menu();

               user.dowork(choice,bookList);
           }

       }

    }
}
